<template>
  <div class="header">
    <div class="collapse-btn" @click="collapseChage">
      <i class="el-icon-menu"></i>
    </div>
    <div class="logo">music后台管理</div>
    <div class="header-right">
      <div class="btn-fullscreen" @click="handleFullSrceen">
        <el-tooltip :content="fullscreen ? '关闭全屏' : '打开全屏'">
          <i class="el-icon-rank"></i>
        </el-tooltip>
      </div>
      <div class="user-avator">
        <img src="../assets/img/user.jpg" alt="头像">
      </div>


      <el-dropdown class="user-name" trigger="click" @command="handleCommand">
        <span class="el-dropdown-link">
          {{username}}
          <i class="el-icon-caret-bottom"></i>
        </span>

        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>


    </div>
  </div>
</template>



<script>
  import bus from '../assets/js/bus.js'
  export default {
    data() {
      return {
        fullscreen: false,
        collapse: false
      }
    },
    computed: {
      username() {
        return localStorage.getItem('username');
      }
    },
    methods: {
      collapseChage() {
        this.collapse = !this.collapse;
        bus.$emit('collapse', this.collapse);
      },
      handleFullSrceen() {
        if (this.fullscreen) {
          this.fullscreen = !this.fullscreen;
          document.exitFullscreen();
        } else {
          this.fullscreen = !this.fullscreen;
          document.documentElement.webkitRequestFullScreen();
        }
      },
      handleCommand (command) {
        if (command === 'logout') {
          localStorage.removeItem('username')
          this.$router.push('/')
        }
      }

    }

  }
</script>

<style scoped>
  .header {
    position: relative;
    background-color: #253041;
    box-sizing: border-box;
    width: 100%;
    height: 70px;
    font-size: 22px;
    color: #fff;
    line-height: 70px;

  }

  .collapse-btn {
    float: left;
    padding: 0 21px;
    cursor: pointer;

  }

  .header .logo {
    position: relative;
    float: left;

  }

  .header-right {
    float: right;
    padding-right: 50px;
    align-items: center;
    display: flex;
  }

  .btn-fullscreen {
    transform: rotate(45deg);
    margin-right: 5px;
    font-size: 20px;
  }

.user-name {
  margin-left: 10px;
}
.user-avator {
  margin-left: 20px;
}

.user-avator img {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
}
.el-dropdown-link {
  color: #fff;
  cursor: pointer;
}


</style>
